<template>
	<view class="i_container">
		<view class="time_box">
			<view class="time_box_top">
				<view class="recode_top">
					<view class="recode_top_item">
						<view class="uni-list-cell-db">
							<picker mode="date" :value="date1" @change="bindDateChange1">
								<view class="uni-input txt_time">{{date1}}</view>
							</picker>
						</view>
					</view>
					<text class="recode_top_center">至</text>
					<view class="recode_top_item">
						<view class="uni-list-cell-db">
							<picker mode="date" :value="date" @change="bindDateChange">
								<view class="uni-input txt_time">{{date}}</view>
							</picker>
						</view>
					</view>
				</view>
				<text class="timeQuery" @click="query">筛选</text>
			</view>
			<view class="list_container">
				<view class="list_c_box">
					<view>
						<view class="txtCon" v-if="consumeList.length == 0">
							<noContent></noContent>
						</view>
						<view v-else>
							<scroll-view scroll-y="true" :style="{height: height}" class="scroll-Y" @scrolltoupper="upper" @scrolltolower="lower"
							@scroll="scroll">
								<view class="l_item_box" v-for="(item, index) in consumeList" :key="index">
									<view class="l_i_b_box">
										<view class="l_ite_top">
											<!-- <text class="s_type">{{item.stationName}}</text> -->
											<text class="s_type">{{item.mealName}}</text>
											<text class="scroll_time">{{item.billTime}}</text>
										</view>
										<view class="l_ite_top">
											<text :class="item.amount > 0 ? 'jiaMoney' : 'jianMoney'">{{getCheckNum(item.amount)}}</text>
											<text class="type_detail" v-if="item.payChannel == 3" @click="jumpDetail(item.orderNo)">详情</text>
										</view>
									</view>
								</view>
								<view class="item_f_box">
									<text class="scroll_time">没有更多数据啦~</text>
								</view>
							</scroll-view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view v-if="isShow" class="tan_box">
			<view class="tan_item">
				<view v-for="(item, index) in boxList" :key="index" class="item_box" :class="{'activeBack' : currentIndexs == index}" @click="jumpTab(item.index)">{{item.txt}}</view>
				<view class="less_con"></view>
			</view>
		</view>
	</view>
</template>

<script>
	import {queryMilkConsumeLog, queryWaterConsumeLog} from '../../common/api/index.js';
	import {_showLoading} from '../../common/js/util.js'
	import noContent from '../../components/no-content.vue'
	export default {
		data() {
			const currentDate = this.getDate({
			    format: true
			})
			const currentDate1 = this.getDate1({
			    format: true
			})
			return {
				tabs:[{
					activeIndex: 0,
					title: '食堂消费'
				},{
					activeIndex: 1,
					title: '热水消费'
				}],
				activeIndex: 0,
				date: currentDate,
				date1: currentDate1,
				height: '600rpx',
				currentPage: 1,
				orgId: '',
				empId: '',
				isShow: false,
				currentIndexs: 0,
				consumeList: [],
				boxList: [
					{index: 0, txt: '全部'},
					{index: 1, txt: '刷卡'},
					{index: 2, txt: '实时二维码'},
					{index: 3, txt: '脱机二维码'},
					{index: 4, txt: '微信付款码'}
				]
			}
		},
		components: {
			noContent
		},
		computed: {
			getCheckNum(amount) {
				return function(amount) {
					if(amount > 0){
						return '-' + Number(amount).toFixed(2);
					} else if(amount < 0){
						return '+' + -Number(amount).toFixed(2);
					}else {
						return amount
					}
				}
			}
		},
		onLoad:function(option){
			this.orgId = option.orgId
			this.empId = option.empId
			this.cardNo = option.cardNo
		},
		onShow:function(){
			let _that = this;
			uni.getSystemInfo({
				success: function (res) {
					_that.height = res.windowHeight - 60 + 'px';
				}
			})
			this._queryMilkConsumeLog()
		},
		methods: {
			jumpDetail(orderNo) {
				uni.navigateTo({
					url: '/pagePayment/qrcode/consumeQrcode1?orderNo=' + orderNo + '&empId=' + this.empId + '&orgId=' + this.orgId
				})
			},
			lower() {},
			upper() {},
			scroll() {},
			jumpTab(index) {
				this.currentIndexs = index;
				this._queryMilkConsumeLog()
				this.isShow = false
			},
			query() {
				this.isShow = true
			}, 
			_queryMilkConsumeLog() {
				_showLoading('加载中...')
				queryMilkConsumeLog({
					loginOrgId: this.orgId,
					appId: 1,
					cardNo: this.cardNo,
					empId: this.empId,
					userId: uni.getStorageSync("s_userId"),
					startDate: this.date1.replace(/-/g, ''),
					endDate: this.date.replace(/-/g, ''),
					currentPage: this.currentPage,
					pageSize: 100,
					payChannel: this.currentIndexs, 
					type: 1
				}).then(res => {
					if(res.resultCode == 0) {
						this.consumeList = res.rows
						uni.hideLoading()
					}else {
						uni.hideLoading()
					}
				}).catch(err => {
					uni.hideLoading()
					console.log(err)
				})
			},
			bindDateChange1: function(e) {
				this.date1 = e.target.value
				this.date1 = this.date1.toString().replace(/\//g, "-")
				this._queryMilkConsumeLog()
			},
			bindDateChange: function(e) {
			    this.date = e.target.value
				this.date = this.date.toString().replace(/\//g, "-")
				this._queryMilkConsumeLog()
			},
			getDate(type) {
			    const date = new Date();
			    let year = date.getFullYear();
			    let month = date.getMonth() + 1;
			    let day = date.getDate();
				
			    month = month > 9 ? month : '0' + month;;
			    day = day > 9 ? day : '0' + day;
			    return `${year}-${month}-${day}`;
			},
			getDate1(type) {
			    const date = new Date();
			    let year = date.getFullYear();
			    let month = date.getMonth() + 1;
			    let day = date.getDate();
				
			    month = month > 9 ? month : '0' + month;;
			    day = day > 9 ? day : '0' + day;
			    return `${year}-${month}-${day}`;
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F8F8F8;
	}
	.i_container {
		background-color: #F8F8F8;
		overflow: hidden;
		.time_box {
			padding: 0 20rpx;
			margin-top: 20rpx;
			.time_box_top {
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				align-items: center;
				background-color: #ffffff;
				padding: 0 20rpx;
				height: 96rpx;
				.recode_top {
					width: 70%;
					display: flex;
					flex-direction: row;
					align-items: center;
					background: #FFFFFF;
					border-radius: 8rpx;
					.recode_top_item {
						display: flex;
						flex: 1;
						justify-content: center;
						.uni-input {
							font-size: 28rpx;
						}
						.txt_time {
							color: #169BD5;
							display: flex;
							justify-content: center;
							align-items: center;
						}
					}
					.recode_top_center {
						font-family: 'Arial Normal', 'Arial';
						font-weight: 400;
						font-size: 28rpx;
						color: #333333;
					}
				}
				.timeQuery {
					font-size: 28rpx;
					font-family: "PingFang-SC-Medium, PingFang-SC";
					font-weight: 500;
					color: #FFFFFF;
					background: #185AFF;
					border-radius: 8rpx;
					padding: 12rpx 24rpx;
				}
			}
			.list_container {
				padding: 10rpx;
				background-color: #FFF;
				.list_c_box {
					padding: 0 10rpx;
					.txtCon {
						width: 100%;
						display: flex;
						flex-direction: column;
						justify-content: center;
						align-items: center;
						margin-top: 30rpx;
					}
					.l_item_box {
						display: flex;
						lex-direction: row;
						align-items: center;
						.l_i_b_box {
							display: flex;
							flex-direction: row;
							justify-content: space-between;
							align-items: center;
							flex: 1;
							border-bottom: 1px solid #dddddd;
							margin-top: 10rpx;
							padding: 0 10rpx;
							.l_ite_top {
								display: flex;
								flex-direction: column;
								justify-content: space-between;
								line-height: 50rpx;
								.s_type {
									font-size: $font-size-base;
									font-family: "PingFangSC-Medium, PingFang SC";
									font-weight: 500;
									color: #6B707A;
								}
								.scroll_time {
									font-size: 24rpx;
									font-family: "PingFangSC-Medium, PingFang SC";
									font-weight: 500;
									color: #6B707A;
								}
								.type_detail {
									font-size: $font-size-base;
									font-family: "PingFangSC-Medium, PingFang SC";
									font-weight: 500;
									color: #6B707A;
									border: 1px solid #ddd;
									display: flex;
									justify-content: center;
									align-items: center;
									border-radius: 5px;
									width: 45px;
								}
							}
						}
					}
					.item_f_box {
						height: 50rpx;
						display: flex;
						justify-content: center;
						align-items: center;
						.scroll_time {
							font-size: 24rpx;
							font-family: "PingFangSC-Medium, PingFang SC";
							font-weight: 500;
							color: #6B707A;
						}
					}
				}
			}
		}
		.tan_box {
			background: rgba(0, 0, 0, .2);
			width: 100%;
			height: 100%;
			display: flex;
			justify-content: center;
			align-items: center;
			position: absolute;
			top: 0;
			z-index: 999;
			.tan_item {
				width: 275px;
				height: 30%;
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				flex-wrap: wrap;
				background: #fff;
				.item_box {
					border: 1px solid #dddddd;
					width: 90px;
					display: flex;
					justify-content: center;
					align-items: center;
					border-bottom: none;
					border-left: none;
				}
				.less_con {
					width: 90px;
					display: flex;
					justify-content: center;
					align-items: center;
					border-top: 1px solid #dddddd;
				}
			}
		}
	}
	.activeBack {
		background: #185AFF;
		color: #ffffff;
	}
</style>